-- Copyright (c) 2025 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.

local log      = require 'mc.logging'
local c_object = require 'mc.orm.object'
local mctp_lib = require 'mctp_lib'

local c_spdm_component = c_object('SpdmComponent') -- SpdmComponent 类

function c_spdm_component:ctor(object, position, path, mdb_name)
    self.mdb_name        = mdb_name
    self.device_name     = object.DeviceName
    self.position        = position
    self.inventory_path  = path
    self.eid             = 0
    self.phy_addr        = 0
    self.endpoint        = nil
    self.dev = {
        ['dev_bus']      = object.DevBus,
        ['dev_device']   = object.DevDevice,
        ['dev_function'] = object.DevFunction
    }
end

function c_spdm_component:init()
    self:get_phy_addr()
end

function c_spdm_component:get_phy_addr()
    local phy_addr = mctp_lib.bdf_to_phy_addr(self.dev.dev_bus, self.dev.dev_device, self.dev.dev_function)
    log:notice("DevBus: %s, DevDevice: %s, DevFunction: %s", self.DevBus, self.DevDevice, self.DevFunction)
    self.phy_addr = phy_addr
end

return c_spdm_component